//
//  Tools.swift
//  Weibo
//
//  Created by 贵永冬 on 16/7/14.
//  Copyright © 2016年 贵永冬. All rights reserved.
//

import Foundation
import UIKit
import SVProgressHUD

//播放声音
func playMusic(musicName : String) {
    dispatch_async(dispatch_queue_create("playMisic", DISPATCH_QUEUE_SERIAL)) {
        let soundURL = NSBundle.mainBundle().URLForResource(musicName, withExtension: "wav")
        var soundID : SystemSoundID = 0
        AudioServicesCreateSystemSoundID(soundURL!, &soundID)
        AudioServicesPlaySystemSound(soundID)
    }
}

/**
 根据RGBA生成颜色
 */
public func RGBA(r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> UIColor {
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}
/**
 根据RGB生成颜色
 */
public func RGB(r:CGFloat, g:CGFloat, b:CGFloat) -> UIColor {
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: 1)
}

public func dissmissHudView(time: Float ) -> Void {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(time*Float(NSEC_PER_SEC))), dispatch_get_main_queue()) {
        SVProgressHUD.dismiss()
    }
}
public func isNewVersion() -> Bool {
    let infoDictionary = NSBundle.mainBundle().infoDictionary
    let nowVersion : NSString = infoDictionary! ["CFBundleVersion"] as! String
    let lastVersion = NSUserDefaults.standardUserDefaults().objectForKey("version")
    if lastVersion == nil {
        return true
    }else {
        let last = lastVersion as! String
        if nowVersion.compare(last) == NSComparisonResult.OrderedDescending {
            return true
        }else {
            NSUserDefaults.standardUserDefaults().setObject(nowVersion, forKey: "version")
            NSUserDefaults.standardUserDefaults().synchronize()
            return false
        }
    }
}

public func saveImageWithImage(image: UIImage) {
    
}



/// 基础色
let BASECOLOR = RGB(237, g: 237, b: 237)
let LINECOLOR = RGB(220, g: 220, b: 220)
let NAVTINTCOLOR = RGB(85, g: 85, b: 85)
let ORGINCOLOR = RGB(254, g: 118, b: 1)
let TEXTBASECOLOR = RGB(120, g: 120, b: 120)
let BLUECOLOR = RGB(82, g: 126, b: 173)
/// 屏幕的宽度
let GYDWindowWidth = UIScreen.mainScreen().bounds.size.width
/// 屏幕的高度
let GYDWindowHeight = UIScreen.mainScreen().bounds.size.height
/// 登录按钮信号
let LOGIN_SIGNAL = "login_signal"
/// 注册按钮信号
let REGIST_SIGNAL = "regist_signal"
/// 关注按钮信号
let FOCUS_SIGNAL = "focus_signal"
///登录成功标识
let LOGIN_SUCCESS = "login_success"
/// 退出登录成功
let LOGINOUT_SUCCESS = "loginout_success"


/// 图片旋转器的当前选中的index
let SELECTEDINDEX = "selectedIndex"
/// 图片选择器的所有图片的url
let ALLIMAGEURL = "allImageUrl"
/// 图片选择器的所有相对于window的frame
let CELLFRAMEDIC = "cellFrameDic"
/// 图片的大小
let CELLIMAGESIZE = "cellIamgeSize"


//新浪微博App Key： 3820804859
//App Secret： f1ae9c0d27f8adde75d4207996309b2b
//回调url http://www.guiyongdong.com
/// OAuth授权需要的key
let WB_App_Key = "3820804859"
/// OAuth授权需要的Secret
let WB_App_Secret = "f1ae9c0d27f8adde75d4207996309b2b"
/// OAuth授权需要的重定向地址
let WB_Redirect_uri = "http://www.guiyongdong.com"
let ACCESS = "access"


